<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<link rel="stylesheet" href="${ctx}/js/ext-3.3.0/resources/css/ext-all.css"/>
	<link href="${ctx}/css/css51.css" media="screen" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="${ctx}/js/jquery-1.3.2.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/ajaxfileupload.js"></script>
	<title>后台用户管理</title>
</head>
<body>
	<!-- 新增/修改 -->
	<div id="nleft" class="nleft" style="background: white;width:100%;">
		<table width="60%" border="0" cellpadding="0" cellspacing="0">
			<tbody>
				<tr bgcolor="#ECF1FA">
					<td colspan="4" width="100" height="30" align="left">&nbsp;&nbsp;修改用户信息</td>
				</tr>
				<tr>
					<td width="100" height="30" align="center">真实姓名</td>
					<td><input type="text" id="userTrueName" name="userTrueName" value="${SESSION_USER.userTrueName!}"/></td>
					<td width="100" height="30" align="center">电子邮件</td>
					<td>
						<input type="text" id="email" name="email" value="${SESSION_USER.email!}"/>
					</td>
				</tr>
				<tr bgcolor="#ECF1FA">
					<td width="100" height="30" align="center">联系电话</td>
					<td>
						<input type="text" id="linkTel" name="linkTel" value="${SESSION_USER.linkTel!}"/>
					</td>
					<td align="center">手机</td>
					<td>
						<input type="text" id="mobilePhone" name="mobilePhone" value="${SESSION_USER.mobilePhone!}"/>
					</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td width="100" height="30" align="center">
						<input type="button" id="btnEdit" value="修改信息" class="long_button" onclick="ajaxUpdate(null)">
					</td>
				</tr>
			</tbody>
		</table>
		<br /><br /><br />
		<table width="60%" border="0" cellpadding="0" cellspacing="0">
			<tbody>
				<tr bgcolor="#ECF1FA">
					<td colspan="4" width="100" height="30" align="left">&nbsp;&nbsp;修改密码</td>
				</tr>
				<tr>
					<td width="100" height="30" align="center">原密码</td>
					<td>
						<input type="password" id="oldPwd" name="oldPwd"/>
					</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr bgcolor="#ECF1FA">
					<td width="100" height="30" align="center">新密码</td>
					<td>
						<input type="password" id="userPass" name="userPass"/>
					</td>
					<td align="center">确认密码</td>
					<td>
						<input type="password" id="enterUserPass" name="enterUserPass"/>
					</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td width="100" height="30" align="center">
						<input type="button" id="btnPwd" value="修改密码" class="long_button" onclick="updatePwd()">
					</td>
				</tr>
			</tbody>
		</table>
		<br /><br />
		<#if SESSION_USER.userPass == '123456'><span style="color:red;font-size:20px;"><b>请修改初始密码，否则无法使用本系统</b></span></#if>
	</div>
</body>
<script type="text/javascript">
	//验证是否数字(param  len <= 0 则验证是否数字，len > 0 则还验证长度)
	function isNumber(value,len){
		var strP = /^\d+(\.\d+)?$/; //验证是否数字
		if(!strP.test(value))return false;
		if(len > 0 && value.length != len)return false;
		return true;
	}
	function ajaxUpdate(pwd){
		if(pwd == null){
			if($("#userTrueName").val() == ""){
				alert("请填写真实姓名！");
				$("#userTrueName").focus();
				return;
			}else if($("#email").val() == ""){
				alert("请填写电子邮件");
				$("#email").focus();
				return;
			}else if(!$("#email").val().match(/^([A-Za-z0-9])(\w)+@(\w)+(\.)(com|com\.cn|net|cn|net\.cn|org|biz|info|gov|gov\.cn|edu|edu\.cn)/)){
				alert("邮箱格式有误！");
				$("#email").focus();
				return;
			}else if($("#linkTel").val() == ""){
				alert("请填写联系电话");
				$("#linkTel").focus();
				return;
			}else if(!isNumber($("#linkTel").val(),0)){
				alert("联系电话只能是数字");
				$("#linkTel").focus();
				return;
			}else if($("#mobilePhone").val() == ""){
				alert("请填写手机号码！");
				$("#mobilePhone").focus();
				return;
			}else if(!isNumber($("#mobilePhone").val(),11)){
				alert("手机号码必须为11位有效数字！");
				$("#mobilePhone").focus();
				return;
			}
		}
		$.ajax({
    		url : "${ctx}/crmuser/ajax/add",
 			data:{
    			id:${SESSION_USER.id?c},
    			userName:encodeURIComponent('${SESSION_USER.userName!}'),
    			userTrueName:$("#userTrueName").val(),
    			userPass:pwd == null ? '${SESSION_USER.userPass!}' : pwd,
    			linkTel:$("#linkTel").val(),
    			mobilePhone:$("#mobilePhone").val(),
    			email:$("#email").val(),
    			roleIds:'${SESSION_USER.roleIds!}',
				userCityNo:'${SESSION_USER.userCityNo!}',
    			cityNo:'${SESSION_USER.cityNo!}',
    			state:${SESSION_USER.state},
				lastLoginTimeString:'${SESSION_USER.lastLoginTime?datetime}',
				isWriteSession:true
 			},
 			type:"post",
 			success:function(data){
 				if(data == "1"){
					if(pwd == null){
						alert("操作成功！");
					}else{
						alert("操作成功,系统将自动退出,请使用新密码重新登录!");
						parent.location.href = "${ctx}/crmuser/logout";
					}
 				}else if(data == "0"){
 					alert("操作失败！");
 				}
 			}
 		});
    }
	function updatePwd(){
		var oldPwd = $("#oldPwd").val();
		var pwd = $("#userPass").val();
		var enterPwd = $("#enterUserPass").val();
		if(oldPwd == "" || pwd == "" || enterPwd == ""){
			alert("新旧密码不能为空，请填写完整");
			return;
		}
		if(oldPwd != "${SESSION_USER.userPass!}"){
			alert("原密码输入错误");
			return;
		}
		if(pwd != enterPwd){
			alert("两次密码输入不一致，请重新输入");
			return;
		}
		ajaxUpdate($("#userPass").val());
	}
</script>
</html>
